﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:InkCanvasControl">
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    <ControlTemplate x:Key="WithCommandPropertyCtrlTemplate" TargetType="{x:Type local:BasePropertyCtrl}">
        <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
            <Grid>
                <ToggleButton   Command="{Binding MakingTriggerCommand}"  
                                Content="{TemplateBinding Content}"
                                x:Name="PART_Switch"  IsThreeState="False" Margin="0">
                </ToggleButton>
                <Popup x:Name="PART_ArrowPopup" StaysOpen="False" IsEnabled="False"
                       Placement="{TemplateBinding Sys_PopupPlacement}" 
                       IsOpen="{Binding IsOpen,ElementName=PART_Popup}"
                       AllowsTransparency="true" 
                       Focusable="false" 
                       PopupAnimation="Fade">
                    <Border x:Name="ArrowContent">
                        <Polygon x:Name="ArrowBorder" IsEnabled="False"  Fill="LightGray" Opacity="0.9"/>
                    </Border>
                </Popup>

                <Popup x:Name="PART_Popup" StaysOpen="False" PlacementTarget="{Binding ElementName=PART_Switch}" 
                       IsOpen="{TemplateBinding Sys_PopupIsOpen}" 
                       HorizontalOffset="{TemplateBinding Sys_PopupHorizontalOffset}"
                       VerticalOffset="{TemplateBinding Sys_PopupVerticalOffset}"
                       Placement="{TemplateBinding Sys_PopupPlacement}"
                       AllowsTransparency="true" Focusable="false"  PopupAnimation="Fade">
                    <Border x:Name="ContentArea" >
                        <Grid Margin="10">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition Height="auto"/>
                            </Grid.RowDefinitions>
                            <Border x:Name="MainBorder" Background="LightGray" Opacity="0.9" CornerRadius="5" Grid.RowSpan="2"/>
                            <ContentControl Content="{TemplateBinding Sys_PopupContent}"/>
                            <StackPanel x:Name="OP" Orientation="Horizontal" Grid.Row="1" Margin="20" Visibility="Collapsed">
                                <StackPanel>
                                    <Button Width="48" Height="48"  Command="{Binding AutoMakingCommand}" Style="{DynamicResource Button_TransparentStyle}">
                                        <Image Source="pack://siteOfOrigin:,,,/images/business/自动制作.png"/>
                                    </Button>
                                    <Border Margin="0,3,0,0" Padding="1,0" CornerRadius="5" Background="{DynamicResource Background_ToolTip}">
                                        <TextBlock  HorizontalAlignment="Center" Text="自动制作" FontFamily="STZhongsong" FontSize="16"/>
                                    </Border>
                                </StackPanel>
                                <StackPanel Margin="15,0,0,0">
                                    <Button Width="48" Height="48"   Command="{Binding ManualMakingCommand}" Style="{DynamicResource Button_TransparentStyle}">
                                        <Image Source="pack://siteOfOrigin:,,,/images/business/手工制作.png"/>
                                    </Button>
                                    <Border Margin="0,3,0,0" Padding="1,0" CornerRadius="5" Background="{DynamicResource Background_ToolTip}">
                                        <TextBlock  HorizontalAlignment="Center" Text="手工制作" FontFamily="STZhongsong" FontSize="16"/>
                                    </Border>
                                </StackPanel>

                            </StackPanel>
                        </Grid>
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Sys_PopupContent" Value="{x:Null}">
                <Setter TargetName="OP" Property="Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="Placement" Value="Left" SourceName="PART_Popup">
                <Setter Property="HorizontalAlignment" Value="Right" TargetName="ArrowBorder"/>
                <Setter Property="VerticalAlignment" Value="Center" TargetName="ArrowBorder"/>
                <Setter Property="Points" Value="0,0 10,10 0,20" TargetName="ArrowBorder"/>
                <Setter Property="Height" Value="48" TargetName="ArrowContent"/>
            </Trigger>
            <Trigger Property="Placement" Value="Right" SourceName="PART_Popup">
                <Setter Property="HorizontalAlignment" Value="Left" TargetName="ArrowBorder"/>
                <Setter Property="VerticalAlignment" Value="Center" TargetName="ArrowBorder"/>
                <Setter Property="Points" Value="10,0 0,10 10,20" TargetName="ArrowBorder"/>
                <Setter Property="Height" Value="48" TargetName="ArrowContent"/>
            </Trigger>
            <Trigger Property="Placement" Value="Top" SourceName="PART_Popup">
                <Setter Property="HorizontalAlignment" Value="Center" TargetName="ArrowBorder"/>
                <Setter Property="VerticalAlignment" Value="Bottom" TargetName="ArrowBorder"/>
                <Setter Property="Points" Value="0,0 10,10 20,0" TargetName="ArrowBorder"/>
                <Setter Property="Width" Value="48" TargetName="ArrowContent"/>
            </Trigger>
            <Trigger Property="Placement" Value="Bottom" SourceName="PART_Popup">
                <Setter Property="HorizontalAlignment" Value="Center" TargetName="ArrowBorder"/>
                <Setter Property="VerticalAlignment" Value="Top" TargetName="ArrowBorder"/>
                <Setter Property="Points" Value="0,10 10,0 20,10" TargetName="ArrowBorder"/>
                <Setter Property="Width" Value="48" TargetName="ArrowContent"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <ControlTemplate x:Key="CommonPropertyCtrlTemplate" TargetType="{x:Type local:BasePropertyCtrl}">
        <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
            <Grid>
                <ToggleButton   IsChecked="{Binding IsOpen,ElementName=PART_Popup}"
                                Content="{TemplateBinding Content}"
                                Width="{TemplateBinding Width}"
                                Height="{TemplateBinding Height}"
                                x:Name="PART_Switch"  IsThreeState="False" Margin="0">
                </ToggleButton>
                <Popup x:Name="PART_ArrowPopup" StaysOpen="False" IsEnabled="False"
                       Placement="{TemplateBinding Sys_PopupPlacement}" 
                       IsOpen="{Binding IsOpen,ElementName=PART_Popup}"
                       AllowsTransparency="true" 
                       Focusable="false" 
                       PopupAnimation="Fade">
                    <Border x:Name="ArrowContent">
                        <Polygon x:Name="ArrowBorder" IsEnabled="False"  Fill="Gray" Opacity="0.9"/>
                    </Border>
                </Popup>

                <Popup x:Name="PART_Popup" StaysOpen="False" PlacementTarget="{Binding ElementName=PART_Switch}" 
                       IsOpen="{TemplateBinding Sys_PopupIsOpen}" 
                       HorizontalOffset="{TemplateBinding Sys_PopupHorizontalOffset}"
                       VerticalOffset="{TemplateBinding Sys_PopupVerticalOffset}"
                       Placement="{TemplateBinding Sys_PopupPlacement}"
                       AllowsTransparency="true" Focusable="false"  PopupAnimation="Fade">
                    <Border x:Name="ContentArea" >
                        <Grid Margin="10">
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition Height="auto"/>
                            </Grid.RowDefinitions>
                            <Border x:Name="MainBorder" Background="Gray" Opacity="0.9" CornerRadius="5" Grid.RowSpan="2"/>
                            <ContentControl Content="{TemplateBinding Sys_PopupContent}"/>
                        </Grid>
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Placement" Value="Left" SourceName="PART_Popup">
                <Setter Property="HorizontalAlignment" Value="Right" TargetName="ArrowBorder"/>
                <Setter Property="VerticalAlignment" Value="Center" TargetName="ArrowBorder"/>
                <Setter Property="Points" Value="0,0 10,10 0,20" TargetName="ArrowBorder"/>
                <Setter Property="Height" Value="48" TargetName="ArrowContent"/>
            </Trigger>
            <Trigger Property="Placement" Value="Right" SourceName="PART_Popup">
                <Setter Property="HorizontalAlignment" Value="Left" TargetName="ArrowBorder"/>
                <Setter Property="VerticalAlignment" Value="Center" TargetName="ArrowBorder"/>
                <Setter Property="Points" Value="10,0 0,10 10,20" TargetName="ArrowBorder"/>
                <Setter Property="Height" Value="48" TargetName="ArrowContent"/>
            </Trigger>
            <Trigger Property="Placement" Value="Top" SourceName="PART_Popup">
                <Setter Property="HorizontalAlignment" Value="Center" TargetName="ArrowBorder"/>
                <Setter Property="VerticalAlignment" Value="Bottom" TargetName="ArrowBorder"/>
                <Setter Property="Points" Value="0,0 10,10 20,0" TargetName="ArrowBorder"/>
                <Setter Property="Width" Value="48" TargetName="ArrowContent"/>
            </Trigger>
            <Trigger Property="Placement" Value="Bottom" SourceName="PART_Popup">
                <Setter Property="HorizontalAlignment" Value="Center" TargetName="ArrowBorder"/>
                <Setter Property="VerticalAlignment" Value="Top" TargetName="ArrowBorder"/>
                <Setter Property="Points" Value="0,10 10,0 20,10" TargetName="ArrowBorder"/>
                <Setter Property="Width" Value="48" TargetName="ArrowContent"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <Style TargetType="{x:Type local:BasePropertyCtrl}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Width" Value="48"/>
        <Setter Property="Height" Value="48"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Background" Value="Transparent"/>
        <Style.Triggers>
            <Trigger Property="Sys_PropertyCtrlType" Value="WithCommand">
                <Setter Property="Template" Value="{StaticResource WithCommandPropertyCtrlTemplate}"/>
            </Trigger>
            <Trigger Property="Sys_PropertyCtrlType" Value="Common">
                <Setter Property="Template" Value="{StaticResource CommonPropertyCtrlTemplate}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>
